#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int nums[N];

int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>nums[i];
	}

	int q;cin>>q;
	while(q--)
	{
		int x,y;cin>>x>>y;
		auto left=lower_bound(nums+1,nums+n+1,x);
		auto right=upper_bound(nums+1,nums+n+1,y);
		cout<<right-left<<endl;
	}
}